//
//  FloorCheckViewController.m
//  SAYAKA_Kitchen
//
//  Created by Rei on 13/07/21.
//  Copyright (c) 2013年 hackathon. All rights reserved.
//

#import "FloorCheckViewController.h"
#import "StockCell.h"

@interface FloorCheckViewController ()<UITableViewDataSource, UITableViewDelegate, StockCellDelegate>
@property (weak, nonatomic) IBOutlet UITableView *stockTableView;
@property (weak, nonatomic) IBOutlet UIButton *closeBtn;
- (IBAction)pushCloseBtn:(id)sender;

@end

@implementation FloorCheckViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.title = @"在庫確認";
    self.navigationController.navigationBar.tintColor = [UIColor darkGrayColor];
    self.stockTableView.delegate = self;
    self.stockTableView.dataSource = self;
    [self.stockTableView registerNib:[UINib nibWithNibName:@"StockCell" bundle:nil] forCellReuseIdentifier:@"StockCell"];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)pushCloseBtn:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"StockCell";
    
    StockCell *cell = [self.stockTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[StockCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    switch (indexPath.row) {
        case 0: {
            cell.nameLabel.text = @"牛肉と豚肉とチキンのカレー";
            cell.stockLabel.text = @"5";
            cell.stockLabel.textColor = [UIColor redColor];
        } break;
        case 1: {
            cell.nameLabel.text = @"さかなカレー";
            cell.stockLabel.text = @"10";
            [cell.stockInfoBtn setEnabled:NO];
        }
        default:
            break;
    }
    cell.stockInfoBtn.tag = indexPath.row;
    cell.delegate = self;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)stockCell:(StockCell *)stockCell didClickedStockInfoBtn:(id)sender {
    NSArray *array = [NSArray arrayWithObjects:@"牛肉と豚肉とチキンのカレー", @"さかなカレー", nil];
    UIButton *button = (UIButton *)sender;
    NSString *message = [NSString stringWithFormat:@"卓上端末に %@ の残り数を送信します。よろしいですか", [array objectAtIndex:button.tag]];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
                                                    message:message
                                                   delegate:self
                                          cancelButtonTitle:@"キャンセル"
                                          otherButtonTitles:@"OK", nil];
    [alert show];
}
@end
